import { Widget, _decorator, Node, PageView, tween, v3 } from 'cc';
import { UIBase } from '../scriptBase/UIBase';
import { UI } from '../enum/UI';
import { GameMgr } from '../manager/GameMgr';
import { CoinItem } from '../uiItem/CoinItem';
import { CoinMgr } from '../manager/CoinMgr';
import { AudioMgr } from '../manager/AudioMgr';
const { ccclass, property, requireComponent } = _decorator;

@ccclass('UIMain')
@requireComponent(Widget)
export class UIMain extends UIBase {
    // @property({ type: PageView })
    private pageView: PageView = null
    // @property({ type: CoinItem })
    private coinItem: CoinItem = null
    // @property({ type: Node })
    private hand: Node = null

    protected onLoad(): void {
        // this.pageView = this.findComp('PageView', PageView)
        // this.coinItem = this.findComp('CoinItem', CoinItem)
        // this.hand = this.findNode('Tip/Hand')

        this.pageView = this.node.getChildByName('PageView').getComponent(PageView);
        this.coinItem = this.node.getChildByName('CoinItem').getComponent(CoinItem);
        this.hand = this.node.getChildByPath('Tip/Hand');
    }

    protected start(): void {
        tween(this.hand).to(1, { position: v3(200, 0, 0) }).to(1, { position: v3(-200, 0, 0) }).union().repeatForever().start()
    }

    public onOpen(data?: any): void {
        this.pageView.scrollToPage(GameMgr.mode, 0)
        this.coinItem.init(CoinMgr.CurCoin)
        AudioMgr.playBgm('主界面音乐')
    }

    public onClose(data?: any): void {
    }

    protected onBtnSettingClick(): void {
        this.open(UI.Setting)
    }

    protected onBtnLuckySpinClick(): void {
        this.open(UI.LuckySpin)
    }

    protected onBtnPassRewardClick(): void {
        this.open(UI.PassReward)
    }

}


